from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

from google.appengine.api import users
from google.appengine.api import images


from handlers.requesthandler import RequestHandler
from handlers.loginhandler import Guestbook

from handlers.videohandler import AddVideo
from handlers.imagehandler import Image

from operation.tools import Tools
from model.video import Video

#class Image (webapp.RequestHandler):
#    def get(self):
#        video = db.get(self.request.get("img_id"))
#        if video.cover:
#            self.response.headers['Content-Type'] = "image/png"
#            self.response.out.write(video.cover)
#        else:
#            self.response.out.write("No image")



class MainPage(RequestHandler):
    def get(self):
        videos = Video.all()
        template_values = {
                        'titles':Tools.namelist,
                        'videos':videos,
                        }
        self.render('index.html', template_values)

#class Clear(RequestHandler):
#    def get(self):
#        videos=Video.all()
#        videos
        


application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                      ('/home', MainPage),
                                      ('/sign', Guestbook),
                                      ('/img', Image),
#                                      ('/clear',Clear)
                                      ('/addvideo', AddVideo)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
